/**
 * Copyright (C) 2010 Alfredo Morresi
 * 
 * This file is part of RainbowLibs project.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package it.rainbowbreeze.libs.data;

import java.util.Calendar;

import android.content.Context;

public abstract class RainbowAppPreferencesDao
	extends RainbowPreferencesDao
{
	//---------- Private fields
	
    protected static final String PROP_APPVERSION = "appVersion";
    protected static final String PROP_INSTALLATION_TIME = "installationTime";
    protected static final String PROP_UNIQUEID = "uniqueId";

	

	
	//---------- Constructors
	public RainbowAppPreferencesDao(Context context, String preferenceKey) {
		super(context, preferenceKey);
	}





	//---------- Public Properties


    
    
    
	//---------- Public Methods

    public String getAppVersion()
    { return mSettings.getString(PROP_APPVERSION, "00.00.00"); }
    public void setAppVersion(String newValue)
    { mEditor.putString(PROP_APPVERSION, newValue); }
    
    
    /**
     * Get the installation time of the application. Useful for
     * application that expires
     * @return
     */
    public long getInstallationTime()
    {
    	long installationTime = mSettings.getLong(PROP_INSTALLATION_TIME, 0);
    	if (0 == installationTime) {
    		//first run, set as installation time current milliseconds
    	    final Calendar c = Calendar.getInstance();
    	    installationTime = c.getTimeInMillis();
    	    //store it
    	    setInstallationTime(installationTime);
    	    save();
    	}
    	return installationTime;
    }
    /**
     * Set the installation time of the application
     * @param newValue
     */
    public void setInstallationTime(long newValue)
    { mEditor.putLong(PROP_INSTALLATION_TIME, newValue); }

    
    /**
     * Return the unique id of the application
     * @return
     */
    public long getUniqueId()
    {
    	long installationTime = mSettings.getLong(PROP_UNIQUEID, 0);
    	if (0 == installationTime) {
    		//first run, set as installation time current milliseconds
    	    final Calendar c = Calendar.getInstance();
    	    installationTime = c.getTimeInMillis();
    	    //store it
    	    mEditor.putLong(PROP_UNIQUEID, installationTime);
    	    save();
    	}
    	return installationTime;
    }
    
    


    //---------- Protected Methods

}